package com.xxx.lib.base

import java.lang.ref.WeakReference

/**
 * p层基类
 */
abstract class BasePresenter<V : IBaseView> {

    /**
     * V层弱引用
     */
    private var weakReference: WeakReference<V>? = null

    /**
     * P层绑定V层
     */
    fun attachView(v: V) {
        if (weakReference == null) weakReference = WeakReference(v)
    }


    /**
     * P层解绑V层
     */
    fun detachView() {
        weakReference?.clear()
        weakReference = null
    }

    /**
     * 获取V层
     */
    protected fun getView(): V? {
        return weakReference?.get()
    }


}
